package com.hs.util;

import java.util.ArrayList;
import java.util.List;

/**
 *  分页工具类，该工具类就可以实现所有的表的分页操作
 */
public class Page<T> {

    private int pageNum;   // 当前页码
    private int pageSize;  // 每页显示条数
    private int startIndex; // 查询的开始下标
    private int count;     // 数据总条数
    private int pageCount;  // 总页数
    // 定义一个集合，来保持分页后查询的数据集合
    private List<T> list = new ArrayList<>();

    public Page(int pageNum, int pageSize, int count) {
        this.pageSize = pageSize;
        this.count = count;
        // 计算总页数
        this.pageCount = (count%pageSize==0)?(count/pageSize):(count/pageSize+1);
        // 判断pageNum的合法性
        if(pageNum>this.pageCount){
            pageNum=this.pageCount;
        }
        if(pageNum<=0){
            pageNum=1;
        }
        this.pageNum = pageNum;
        // 计算开始下标
        this.startIndex = (this.pageNum-1)*this.pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}



